package com.kingdee.pda.ui.interception_registr;

import android.content.Context;
import android.text.TextUtils;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;

import java.util.HashMap;
import java.util.List;

/**
 * @author：dlj
 * @data：2022/5/6
 */
public class InterceptionRegistrPresenter implements InterceptionRegistrContract.IOutCheckPresenter {
    private Context context;
    private InterceptionRegistrContract.IOutCheckView view;

    public InterceptionRegistrPresenter(Context context, InterceptionRegistrContract.IOutCheckView view) {
        this.context = context;
        this.view = view;
    }

    @Override
    public void stockOutInterception(String mailNo, String billNo, String operation) {
        HashMap<String, Object> map = new HashMap<>();
        if (!TextUtils.isEmpty(mailNo)) {
            map.put("mailNo", mailNo);
        }
        if (!TextUtils.isEmpty(billNo)) {
            map.put("billNo", billNo);
        }

        MyObserver myObserver = new MyObserver<List<InterceptionOrderBean>>(context) {
            @Override
            public void onSuccess(BaseResponse<List<InterceptionOrderBean>> result) {
                view.stockOutInterceptionSuccess(result.data, result.message, operation);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.stockOutInterceptionFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
                .stockOutInterception(ConstantUtil.INTERCEPTION_RESISTR, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
